<template>
  <a-card :bordered="false">
      <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="银行流水号">
              <j-input placeholder="请输入银行流水号" v-model="queryParam.bankTransNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="收款单位名称">
                <select-Company-input  v-model="queryParam.payeeUnit" placeholder="请选择收款单位" />
              </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="汇款单位名称">
                <j-input placeholder="请输入汇款单位名称" v-model="queryParam.remittanceAcntName"></j-input>
              </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="汇款金额">
              <a-input-number placeholder="请输入最小值" class="query-group-cust" :precision="2" v-model="queryParam.remittanceAmount_begin" style="width:calc(50% - 15px);"></a-input-number>
              <span class="query-group-split-cust"></span>
              <a-input-number placeholder="请输入最大值" class="query-group-cust" :precision="2" :min="queryParam.remittanceAmount_begin" v-model="queryParam.remittanceAmount_end" style="width:calc(50% - 15px);"></a-input-number>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="汇款日期">
              <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.remittanceDate_begin" style="width:calc(50% - 15px);"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.remittanceDate_end" style="width:calc(50% - 15px);"></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="流水类型">
              <j-dict-select-tag type="list" v-model="queryParam.statementType" dictCode="statement_type" placeholder="请选择流水类型"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="收款申请单状态">
              <j-dict-select-tag type="list" v-model="queryParam.collectStatus" dictCode="collect_status" placeholder="请选择收款申请单状态"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('ERP银行流水表')" :disabled="isDisabledAuth('erpFinanceBankStatementBill:export')">导出</a-button>
      <!--<a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpFinanceBankStatementBill:import')">导入</a-button>
      </a-upload>
      -->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <span v-if="selectedRowKeys.length > 0">
        <!-- <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpFinanceBankStatementBill:delete')"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu> -->
        <a-popconfirm :title="'确定标记这'+selectedRowKeys.length+'条流水为项目回款吗？标记后会自动发起收款申请流程'" @confirm="() => handleMarkBatchData(null,'payment_collection')">
          <a-button
                    type="primary"
                    :disabled="isDisabledAuth('erpFinanceBankStatementBill:delete')">标记项目回款</a-button>
        </a-popconfirm>
        <a-popconfirm :title="'确定标记这'+selectedRowKeys.length+'条流水为保证金回款吗？标记后会自动发起收款申请流程'" @confirm="() => handleMarkBatchData(null,'bond')">
          <a-button
                    type="primary"
                    :disabled="isDisabledAuth('erpFinanceBankStatementBill:delete')">标记保证金回款</a-button>
        </a-popconfirm>
        <a-popconfirm :title="'确定标记这'+selectedRowKeys.length+'条流水为其他回款吗？标记后无法修改'" @confirm="() => handleMarkBatchData(null,'other')">
          <a-button
                    type="primary"
                    :disabled="isDisabledAuth('erpFinanceBankStatementBill:delete')">标记其他回款</a-button>
        </a-popconfirm>
      </span>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :components="draggableComponent"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,getCheckboxProps:getCheckboxProps,fixed:true}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <template slot="status" slot-scope="status">
           <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a-button v-if="record.statementType=='payment_collection' || record.statementType=='bond' || record.collectStatus!='init'"
          type="primary" size="small" @click="getCollectDetail(record)"
                    :disabled="isDisabledAuth('erpFinanceBankStatementBill:delete')">查看收款单</a-button>
          <a-divider type="vertical"/>
          <a-button v-if="record.collectStatus=='process_cancel' || record.collectStatus=='process_return' || (record.collectStatus=='init' && record.statementType=='other')"
          type="primary" size="small" @click="remarkType(record)"
                    :disabled="isDisabledAuth('erpFinanceBankStatementBill:delete')">重新标记</a-button>
        </span>
      </a-table>
    </div>
    <a-modal v-model="flag" title="重新标记" @cancel="()=>{this.$set(this.model,'statementType',''),this.$set(this.model,'id','')}" @ok="okReloadStatment">
      <a-row :gutter="24">
        <a-col>
          <b>当前流水类型：{{statementTypeTxt}}</b>
          <j-input  v-model="model.id" style="width:100%;display:none" />
        </a-col>
        <a-col>
          <a-form-item label="调整后流水类型">
            <j-dict-select-tag type="list" v-model="model.statementType" dictCode="statement_type" placeholder="请选择流水类型" style="width:100%"/>
          </a-form-item>
        </a-col>
        <a-col>
          注: 重新标记后，会重新调整收款申请的类型并重新发起流程。
        </a-col>
      </a-row>
    </a-modal>
    <ErpFinanceKingdeeCollectMoneyBillListPenetrate ref="collectMoneyBillListPenetrate"></ErpFinanceKingdeeCollectMoneyBillListPenetrate>
    <erp-finance-bank-statement-bill-modal ref="modalForm" @ok="modalFormOk"></erp-finance-bank-statement-bill-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ErpFinanceBankStatementBillModal from './modules/ErpFinanceBankStatementBillModal'
  import { getAction,postAction } from '@/api/manage'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
  import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
  import ErpFinanceKingdeeCollectMoneyBillListPenetrate from '@/views/scy/penetrate/ErpFinanceKingdeeCollectMoneyBillListPenetrate'

  export default {
    name: 'ErpFinanceBankStatementBillList',
    mixins:[JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ErpFinanceBankStatementBillModal,
      SelectCompanyInput,
      ErpFinanceKingdeeCollectMoneyBillListPenetrate
    },
    data () {
      return {
        description: 'ERP银行流水表管理页面',
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          // {
          //   title:'金蝶主键id',
          //   align:"center",
          //   dataIndex: 'kingdeeId',
          // },
          {
            title:'银行流水号',
            align:"center",
            dataIndex: 'bankTransNo',
            width:180,
            ellipsis: true,
          },
          {
            title:'收款公司',
            align:"center",
            dataIndex: 'payeeUnit_dictText',
            width:180,
            ellipsis: true,
          },
          {
            title:'收款账号',
            align:"center",
            dataIndex: 'payeeAccountNo',
            width:180,
            ellipsis: true,
          },
          {
            title:'收款银行',
            align:"center",
            dataIndex: 'bankName',
            width:180,
            ellipsis: true,
          },
          {
            title:'汇款日期',
            align:"center",
            dataIndex: 'remittanceDate',
            width:100,
            ellipsis: true,
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'汇款金额',
            align:"center",
            dataIndex: 'remittanceAmount',
            width:80,
            ellipsis: true,
          },
          {
            title:'汇款单位',
            align:"center",
            dataIndex: 'remittanceAcntName',
            width:180,
            ellipsis: true,
          },
          {
            title:'汇款账号',
            align:"center",
            dataIndex: 'remittanceBankAccount',
            width:180,
            ellipsis: true,
          },
          {
            title:'汇款银行',
            align:"center",
            dataIndex: 'remittanceBankName',
            width:120,
            ellipsis: true,
          },
          {
            title:'摘要',
            align:"center",
            dataIndex: 'remark',
            width: 150,
            ellipsis: true,
          },
          {
            title:'支付方式',
            align:"center",
            dataIndex: 'kingdeePayMode_dictText',
            width:100,
            ellipsis: true,
          },
          {
            title:'流水类型',
            fixed:"right",
            align:"center",
            dataIndex: 'statementType_dictText',
            width:100,
            ellipsis: true,
          },
          {
            title:'收款申请单状态',
            fixed:"right",
            align:"center",
            dataIndex: 'collectStatus_dictText',
            width:130,
            ellipsis: true,
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:160,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          markBatch:"/api/erp/finance/bankstatement/erpFinanceBankStatementBill/markBatch",
          list: "/api/erp/finance/bankstatement/erpFinanceBankStatementBill/list",
          delete: "/api/erp/finance/bankstatement/erpFinanceBankStatementBill/delete",
          deleteBatch: "/api/erp/finance/bankstatement/erpFinanceBankStatementBill/deleteBatch",
          exportXlsUrl: "/api/erp/finance/bankstatement/erpFinanceBankStatementBill/exportXls",
          importExcelUrl: "/api/erp/finance/bankstatement/erpFinanceBankStatementBill/importExcel",
        },
         /* 排序参数 */
        isorter: {
          column: 'bankTransNo',
          order: 'desc'
        },
        dictOptions:{},
        superFieldList:[],
        flag:false,
        statementType:null,
        statementTypeTxt:null,
        model:{}
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      okReloadStatment(){
          if(!this.model.statementType){
            this.$message.warning('请选择调整后的类型');
            return;
          }
          if(this.model.statementType==this.statementType){
            this.$message.warning('无法转化为相同的类型');
            return;
          }else if(this.model.statementType=="init"){
            this.$message.warning('类型选择错误');
            return;
          }
          let params={ids:this.model.id,'statementStatus':this.model.statementType,'operType':'change'}
          getAction(this.url.markBatch,params).then((res) => {
            if (res.success) {
              this.$message.success(res.message)
              this.flag=false;
              this.loadData();
              this.onClearSelected()
              this.$set(this.model,'statementType','');
              this.$set(this.model,'id','');
            }else{
              this.$message.error(res.message)
            }
        })
      },
      remarkType(record){
        this.flag=true;
        this.statementType=record.statementType;
        this.statementTypeTxt=record.statementType_dictText
        this.$set(this.model,'id',record.id);
      },
      getCollectDetail(record){
        //先清空数据
        this.$refs.collectMoneyBillListPenetrate.dataSource = []
        this.$refs.collectMoneyBillListPenetrate.ipagination.total = 0
        //查询数据
        this.$refs.collectMoneyBillListPenetrate.loading = true
        this.$refs.collectMoneyBillListPenetrate.bankStatement = record
        this.$refs.collectMoneyBillListPenetrate.bankStatementId = record.id
        this.$refs.collectMoneyBillListPenetrate.searchReset()
        //打开弹窗
        this.$refs.collectMoneyBillListPenetrate.visible = true
      },
      //流程审批结束禁用
      getCheckboxProps(record) {
        return {
          props: {
            disabled: record.statementType !== "init"
          }
        }
      },
      handleMarkBatchData(record,statementType){
        let params=null;
        if(record){
          params={ids:record.id}
        }else{
          var ids = ''
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ','
          }
          params={ids:ids,'statementStatus':statementType,'operType':'mark'}
        }
        getAction(this.url.markBatch,params).then((res) => {
          if (res.success) {
            this.$message.success(res.message)
            this.loadData();
            this.onClearSelected()
          }else{
            this.$message.error(res.message)
          }
        })
      },
      initDictConfig(){
      },
      handleDetail: function (record) {
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = '详情';
        this.$refs.modalForm.disableSubmit = true;
    },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'kingdeeId',text:'金蝶主键id',dictCode:''})
        fieldList.push({type:'string',value:'bankTransNo',text:'银行流水号',dictCode:''})
        fieldList.push({type:'string',value:'payeeUnit',text:'收款公司',dictCode:''})
        fieldList.push({type:'date',value:'remittanceDate',text:'汇款日期'})
        fieldList.push({type:'BigDecimal',value:'remittanceAmount',text:'汇款金额',dictCode:''})
        fieldList.push({type:'string',value:'remittanceUnit',text:'汇款单位',dictCode:''})
        fieldList.push({type:'string',value:'payeeAccountNo',text:'收款账号',dictCode:''})
        fieldList.push({type:'string',value:'bankName',text:'收款银行',dictCode:''})
        fieldList.push({type:'Text',value:'remark',text:'摘要',dictCode:''})
        fieldList.push({type:'string',value:'payMode',text:'支付方式',dictCode:''})
        fieldList.push({type:'string',value:'statementType',text:'流水类型',dictCode:''})
        fieldList.push({type:'string',value:'collectStatus',text:'收款申请状态',dictCode:''})
        fieldList.push({type:'string',value:'financeCollectId',text:'收款单id',dictCode:''})
        fieldList.push({type:'string',value:'kingdeeBillId',text:'金蝶流水id',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
